package org.dawning.shop.core.base.repository;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import org.dawning.shop.core.base.BaseEntity;
import org.dawning.shop.core.utils.IdGenerator;
import java.util.Date;


/**
 * Created by L on 2017/6/12.
 * 数据库表基类
 */
@Data
@JsonIgnoreProperties(value={"logicDelete"})
public class RepositoryEntity extends BaseEntity {

    protected static final int LOGIC_DELETE = 1;
    protected static final int NORMAL_DELETE = 0;

    /**
     * 唯一标识
     */
    private String id;
    /**
     * 创建时间
     */
    private Date createDate;
    /**
     * 最后更新时间
     */
    private Date updateDate;
    /**
     * 逻辑删除，默认false
     */
    private Integer logicDelete;

    /**
     * 第一次生成对象时初始化
     */
    public void preInsert(){
        this.setId(IdGenerator.create24Id());
        this.setCreateDate(new Date(new Date().getTime()));
        this.setUpdateDate(new Date(new Date().getTime()));
        this.setLogicDelete(NORMAL_DELETE);
    }
    /**
     * 修改数据时，更新时间
     */
    public void preUpdate(){
        this.setUpdateDate(new Date(new Date().getTime()));
    }

    public void logicDelete(){
        this.setUpdateDate(new Date(new Date().getTime()));
        this.setLogicDelete(LOGIC_DELETE);
    }



}
